#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/un.h>
#include <unistd.h>
#include <stdlib.h>

int main()
{
	int sockfd;
	int len;
	struct sockaddr_un address;
	int result;
	char ch = 'A';

	//creat no-named socket
	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);

	//name sockfd as per local server
	address.sun_family = AF_UNIX;
	strcpy(address.sun_path, "local_server_socket");
	len = sizeof(address);

	//connect local client socket to local server socket
	result = connect(sockfd, (struct sockaddr *)&address, len);
	
	if(result == -1) {
		perror("oops: client1");
		exit(1);
	}

	//send and revd message via socket	
	printf("delay 3 seconds to send char to server socket.\n");
	sleep(3);
	write(sockfd, &ch, 1);

	printf("read more ...");
	read(sockfd, &ch, 1);
	printf("read output is \"%c\"", ch);

	printf("char frmo server = %c\n", ch);
	close(sockfd);
	exit(0);
}
